8038156c: 27 bd ff c8  ADDIU sp, sp, 0xffffffc8 (-56)

80381570: af a0 00 04  SW r0, sp, 0x4 (4)                  [sp + 0x04] = 0;
80381574: 10 80 00 81  BEQ r0, a0, 0x8038177c (pc + 0x204) if (arg1 == 0) goto 0x8038177c;
80381578: 00 00 00 00  NOP

*
8038157c: 8c 88 00 04  LW t0, a0, 0x4 (4)                  t0 = arg1->off0x04
80381580: 8c 84 00 00  LW a0, a0, 0x0 (0)                  arg1 = arg1->off0x00

80381584: 85 09 00 0a  LH t1, t0, 0xa (10)                     t1 = t0->off0x0a
80381588: 85 0a 00 0e  LH t2, t0, 0xe (14)                     t2 = t0->off0x0e
8038158c: 85 0b 00 10  LH t3, t0, 0x10 (16)                    t3 = t0->off0x10
80381590: 85 0c 00 14  LH t4, t0, 0x14 (20)                    t4 = t0->off0x14
80381594: 01 47 70 23  SUBU t6, t2, a3
80381598: 01 69 78 23  SUBU t7, t3, t1
8038159c: 01 cf 00 19  MULTU t6, t7                            lo = (t0->off0x0e - arg4) * (t0->off0x10 - t0->off0x0a)
803815a0: 01 8a 70 23  SUBU t6, t4, t2
803815a4: 01 25 c8 23  SUBU t9, t1, a1
803815a8: 00 00 c0 12  MFLO t8
803815ac: 00 00 00 00  NOP
803815b0: 00 00 00 00  NOP
803815b4: 03 2e 00 19  MULTU t9, t6                            lo = (t0->off0x0a - arg2) * (t0->off0x14 - t0->off0x0e)
803815b8: 00 00 78 12  MFLO t7
803815bc: 03 0f c8 23  SUBU t9, t8, t7                         t9 = (t0->off0x0e - arg4) * (t0->off0x10 - t0->off0x0a) - (t0->off0x0a - arg2) * (t0->off0x14 - t0->off0x0e)
803815c0: 07 21 00 03  BGEZ t9, 0x803815d0 (pc + 0xc)      if ((t0->off0x0e - arg4)*(t0->off0x10 - t0->off0x0a)-(t0->off0x0a - arg2)*(t0->off0x14 - t0->off0x0e) >= 0) goto 0x803815d0;
803815c4: 00 00 00 00  NOP

803815c8: 10 00 00 6a  BEQ r0, r0, 0x80381774 (pc + 0x1a8) goto 0x80381774;
803815cc: 00 00 00 00  NOP

*
803815d0: 85 0d 00 16  LH t5, t0, 0x16 (22)
803815d4: 85 0e 00 1a  LH t6, t0, 0x1a (26)
803815d8: af ae 00 1c  SW t6, sp, 0x1c (28)                    [sp + 0x1c] = t0->off0x1a
803815dc: 01 87 c0 23  SUBU t8, t4, a3
803815e0: 01 ab 78 23  SUBU t7, t5, t3
803815e4: 03 0f 00 19  MULTU t8, t7                            lo = (t0->off0x14 - arg4) * (t0->off0x16 - t0->off0x10)
803815e8: 8f b8 00 1c  LW t8, sp, 0x1c (28)
803815ec: 01 65 70 23  SUBU t6, t3, a1
803815f0: 03 0c 78 23  SUBU t7, t8, t4
803815f4: 00 00 c8 12  MFLO t9
803815f8: 00 00 00 00  NOP
803815fc: 00 00 00 00  NOP
80381600: 01 cf 00 19  MULTU t6, t7                            lo = (t0->off0x10 - arg2) * (t0->off0x1a - t0->off0x14)
80381604: 00 00 c0 12  MFLO t8
80381608: 03 38 70 23  SUBU t6, t9, t8
8038160c: 05 c1 00 03  BGEZ t6, 0x8038161c (pc + 0xc)      if ((t0->off0x14 - arg4)*(t0->off0x16 - t0->off0x10)-(t0->off0x10 - arg2)*(t0->off0x1a - t0->off0x14) >= 0) goto 0x8038161c;
80381610: 00 00 00 00  NOP

80381614: 10 00 00 57  BEQ r0, r0, 0x80381774 (pc + 0x15c) goto 0x80381774;
80381618: 00 00 00 00  NOP

*
8038161c: 8f af 00 1c  LW t7, sp, 0x1c (28)
80381620: 01 2d c0 23  SUBU t8, t1, t5
80381624: 01 e7 c8 23  SUBU t9, t7, a3
80381628: 03 38 00 19  MULTU t9, t8                            lo = (t0->off0x1a - arg4) * (t0->off0x0a - t0->off0x16)
8038162c: 01 a5 c8 23  SUBU t9, t5, a1
80381630: 01 4f c0 23  SUBU t8, t2, t7
80381634: 00 00 70 12  MFLO t6
80381638: 00 00 00 00  NOP
8038163c: 00 00 00 00  NOP
80381640: 03 38 00 19  MULTU t9, t8                            lo = (t0->off0x16 - arg2) * (t0->off0x0e - t0->off0x1a)
80381644: 00 00 78 12  MFLO t7
80381648: 01 cf c8 23  SUBU t9, t6, t7
8038164c: 07 21 00 03  BGEZ t9, 0x8038165c (pc + 0xc)      if ((t0->off0x1a - arg4)*(t0->off0x0a - t0->off0x16)-(t0->off0x16 - arg2)*(t0->off0x0e - t0->off0x1a) >= 0) goto 0x8038165c;
80381650: 00 00 00 00  NOP

80381654: 10 00 00 47  BEQ r0, r0, 0x80381774 (pc + 0x11c) goto 0x80381774;
80381658: 00 00 00 00  NOP

*
8038165c: 3c 18 80 36  LUI t8, 0x8036 (32822)
80381660: 87 18 11 80  LH t8, t8, 0x1180 (4480)
80381664: 13 00 00 09  BEQ r0, t8, 0x8038168c (pc + 0x24)  if (*(0x80361180) == 0) goto 0x8038168c;
80381668: 00 00 00 00  NOP

8038166c: 81 0e 00 04  LB t6, t0, 0x4 (4)
80381670: 31 cf 00 02  ANDI t7, t6, 0x2 (2)
80381674: 11 e0 00 03  BEQ r0, t7, 0x80381684 (pc + 0xc)   if ((t0->off0x04 & 2) == 0) goto 0x80381684;
80381678: 00 00 00 00  NOP

8038167c: 10 00 00 3d  BEQ r0, r0, 0x80381774 (pc + 0xf4)  goto 0x80381774;
80381680: 00 00 00 00  NOP

*
80381684: 10 00 00 07  BEQ r0, r0, 0x803816a4 (pc + 0x1c)  goto 0x803816a4;
80381688: 00 00 00 00  NOP

*
8038168c: 85 19 00 00  LH t9, t0, 0x0 (0)
80381690: 24 01 00 72  ADDIU at, r0, 0x72 (114)
80381694: 17 21 00 03  BNE t9, at, 0x803816a4 (pc + 0xc)   if (to->off0x00 != 0x72) goto 0x803816a4;
80381698: 00 00 00 00  NOP

8038169c: 10 00 00 35  BEQ r0, r0, 0x80381774 (pc + 0xd4)  goto 0x80381774;
803816a0: 00 00 00 00  NOP

**
803816a4: c5 04 00 1c  LWC1 f4, t0, 0x1c (28)
803816a8: e7 a4 00 18  SWC1 f4, sp, 0x18 (24)              [sp + 0x18] = t0->off0x1c;

803816ac: c5 06 00 20  LWC1 f6, t0, 0x20 (32)
803816b0: e7 a6 00 14  SWC1 f6, sp, 0x14 (20)              [sp + 0x14] = t0->off0x20;

803816b4: c5 08 00 24  LWC1 f8, t0, 0x24 (36)
803816b8: e7 a8 00 10  SWC1 f8, sp, 0x10 (16)              [sp + 0x10] = t0->off0x24;

803816bc: c5 0a 00 28  LWC1 f10, t0, 0x28 (40)
803816c0: e7 aa 00 0c  SWC1 f10, sp, 0xc (12)              [sp + 0x0c] = t0->off0x28;

803816c4: c7 b0 00 14  LWC1 f16, sp, 0x14 (20)
803816c8: 44 80 90 00  MTC1 r0, f18
803816cc: 00 00 00 00  NOP
803816d0: 46 12 80 32  C.EQ.S f16, f18
803816d4: 00 00 00 00  NOP
803816d8: 45 00 00 03  BC1F 0x803816e8 (pc + 0xc)          if ([sp + 0x14] != 0) goto 0x803816e8;
803816dc: 00 00 00 00  NOP

803816e0: 10 00 00 24  BEQ r0, r0, 0x80381774 (pc + 0x90)  goto 0x80381774;
803816e4: 00 00 00 00  NOP

*
803816e8: 44 85 20 00  MTC1 a1, f4
803816ec: 44 87 90 00  MTC1 a3, f18
803816f0: c7 a8 00 18  LWC1 f8, sp, 0x18 (24)
803816f4: 46 80 21 a0  CVT.S.W f6, f4
803816f8: c7 b0 00 10  LWC1 f16, sp, 0x10 (16)
803816fc: 46 80 91 20  CVT.S.W f4, f18
80381700: 46 08 32 82  MUL.S f10, f6, f8                       f10 = arg2 * [sp + 0x18]
80381704: c7 b2 00 0c  LWC1 f18, sp, 0xc (12)
80381708: 46 04 81 82  MUL.S f6, f16, f4                       f6 = [sp + 0x10] * arg4
8038170c: 46 06 52 00  ADD.S f8, f10, f6                       f8 = arg2 * [sp + 0x18] + [sp + 0x10] * arg4
80381710: c7 aa 00 14  LWC1 f10, sp, 0x14 (20)
80381714: 46 12 44 00  ADD.S f16, f8, f18                      f16 = arg2 * [sp + 0x18] + [sp + 0x10] * arg4 + [sp + 0x0c]
80381718: 46 00 81 07  NEG.S f4, f16
8038171c: 46 0a 21 83  DIV.S f6, f4, f10
80381720: e7 a6 00 08  SWC1 f6, sp, 0x8 (8)                [sp + 0x08] = -(arg2 * [sp + 0x18] + [sp + 0x10] * arg4 + [sp + 0x0c]) / [sp + 0x14];

80381724: 44 86 20 00  MTC1 a2, f4
80381728: 3c 01 c2 9c  LUI at, 0xc29c (49820)
8038172c: 44 81 90 00  MTC1 at, f18                            f18 = -78.0
80381730: c7 a8 00 08  LWC1 f8, sp, 0x8 (8)
80381734: 46 80 22 a0  CVT.S.W f10, f4                         f10 = (float)arg3
80381738: 46 12 44 00  ADD.S f16, f8, f18                      f16 = [sp + 0x08] - 78.0
8038173c: 44 80 40 00  MTC1 r0, f8
80381740: 46 10 51 81  SUB.S f6, f10, f16                      f6 = (float)arg3 - [sp + 0x08] + 78.0
80381744: 46 08 30 3c  C.LT.S f6, f8
80381748: 00 00 00 00  NOP
8038174c: 45 00 00 03  BC1F 0x8038175c (pc + 0xc)          if ((float)arg3 - [sp + 0x08] + 78.0 >= 0) goto 0x8038175c;
80381750: 00 00 00 00  NOP

80381754: 10 00 00 07  BEQ r0, r0, 0x80381774 (pc + 0x1c)  goto 0x80381774;
80381758: 00 00 00 00  NOP

*
8038175c: c7 b2 00 08  LWC1 f18, sp, 0x8 (8)
80381760: 8f b8 00 48  LW t8, sp, 0x48 (72)
80381764: e7 12 00 00  SWC1 f18, t8, 0x0 (0)               *[sp + 0x48] = [sp + 0x08];

80381768: af a8 00 04  SW t0, sp, 0x4 (4)                  [sp + 0x04] = t0;

8038176c: 10 00 00 03  BEQ r0, r0, 0x8038177c (pc + 0xc)   goto 0x8038177c;
80381770: 00 00 00 00  NOP

*******
80381774: 14 80 ff 81  BNE a0, r0, 0x8038157c (pc - 0x1fc) if (arg1 != 0) goto 0x8038157c;
80381778: 00 00 00 00  NOP

**
8038177c: 10 00 00 03  BEQ r0, r0, 0x8038178c (pc + 0xc)
80381780: 8f a2 00 04  LW v0, sp, 0x4 (4)
80381784: 10 00 00 01  BEQ r0, r0, 0x8038178c (pc + 0x4)
80381788: 00 00 00 00  NOP
8038178c: 03 e0 00 08  JR ra
80381790: 27 bd 00 38  ADDIU sp, sp, 0x38 (56)             return [sp + 0x04];



[sp + 0x04] = 0;
if (arg1 == 0) goto 0x8038177c;
8038157c:
t0 = arg1->off0x04
arg1 = arg1->off0x00
if ((t0->off0x0e - arg4)*(t0->off0x10 - t0->off0x0a)-(t0->off0x0a - arg2)*(t0->off0x14 - t0->off0x0e) >= 0) goto 0x803815d0;
goto 0x80381774;
803815d0:
if ((t0->off0x14 - arg4)*(t0->off0x16 - t0->off0x10)-(t0->off0x10 - arg2)*(t0->off0x1a - t0->off0x14) >= 0) goto 0x8038161c;
goto 0x80381774;
8038161c:
if ((t0->off0x1a - arg4)*(t0->off0x0a - t0->off0x16)-(t0->off0x16 - arg2)*(t0->off0x0e - t0->off0x1a) >= 0) goto 0x8038165c;
goto 0x80381774;
8038165c:
if (*(0x80361180) == 0) goto 0x8038168c;
if ((t0->off0x04 & 2) == 0) goto 0x80381684;
goto 0x80381774;
80381684:
goto 0x803816a4;
8038168c:
if (to->off0x00 != 0x72) goto 0x803816a4;
goto 0x80381774;
803816a4:803816a4:
[sp + 0x18] = t0->off0x1c;
[sp + 0x14] = t0->off0x20;
[sp + 0x10] = t0->off0x24;
[sp + 0x0c] = t0->off0x28;
if ([sp + 0x14] != 0) goto 0x803816e8;
goto 0x80381774;
803816e8:
[sp + 0x08] = -(arg2 * [sp + 0x18] + [sp + 0x10] * arg4 + [sp + 0x0c]) / [sp + 0x14];
if ((float)arg3 - [sp + 0x08] + 78.0 >= 0) goto 0x8038175c;
goto 0x80381774;
8038175c:
*[sp + 0x48] = [sp + 0x08];
[sp + 0x04] = t0;
goto 0x8038177c;
80381774:80381774:80381774:80381774:80381774:80381774:80381774:
if (arg1 != 0) goto 0x8038157c;
8038177c:8038177c:
return [sp + 0x04];




[sp + 0x04] = 0;
if (arg1 == 0) goto 0x8038177c;
8038157c:

t0 = arg1->off0x04
arg1 = arg1->off0x00

if ((t0->off0x0e - arg4)*(t0->off0x10 - t0->off0x0a)-(t0->off0x0a - arg2)*(t0->off0x14 - t0->off0x0e) >= 0) goto 0x803815d0;
    goto 0x80381774;
803815d0:

if ((t0->off0x14 - arg4)*(t0->off0x16 - t0->off0x10)-(t0->off0x10 - arg2)*(t0->off0x1a - t0->off0x14) >= 0) goto 0x8038161c;
    goto 0x80381774;
8038161c:

if ((t0->off0x1a - arg4)*(t0->off0x0a - t0->off0x16)-(t0->off0x16 - arg2)*(t0->off0x0e - t0->off0x1a) >= 0) goto 0x8038165c;
    goto 0x80381774;
8038165c:

if (*(0x80361180) == 0) goto 0x8038168c;
    if ((t0->off0x04 & 2) == 0) goto 0x80381684;
        goto 0x80381774;
    80381684:
goto 0x803816a4;
8038168c:
    if (to->off0x00 != 0x72) goto 0x803816a4;
        goto 0x80381774;
    803816a4:
803816a4:

[sp + 0x18] = t0->off0x1c;
[sp + 0x14] = t0->off0x20;
[sp + 0x10] = t0->off0x24;
[sp + 0x0c] = t0->off0x28;

if ([sp + 0x14] != 0) goto 0x803816e8;
    goto 0x80381774;
803816e8:

[sp + 0x08] = -(arg2 * [sp + 0x18] + [sp + 0x10] * arg4 + [sp + 0x0c]) / [sp + 0x14];
if ((float)arg3 - [sp + 0x08] + 78.0 >= 0) goto 0x8038175c;
    goto 0x80381774;
8038175c:

*[sp + 0x48] = [sp + 0x08];

[sp + 0x04] = t0;
goto 0x8038177c;
80381774:80381774:80381774:80381774:80381774:80381774:80381774:
if (arg1 != 0) goto 0x8038157c;
8038177c:8038177c:

return [sp + 0x04];



typedef struct tagRTSOLIDITY {
    short command;     /* 2    @ 0x00 */
    short extra;       /* 2    @ 0x02 */
    char  unknown1     /* 1    @ 0x04 */
    char  unknown2     /* 1    @ 0x05 */
    short ymin         /* 2    @ 0x06 */
    short ymax         /* 2    @ 0x08 */
    short pts[3][3];   /* 0x12 @ 0x0a */  /* (0a 0c 0e) (10 12 14) (16 18 1a) */
    float norm[3]      /* 0x0c @ 0x1c */  /* (1c 20 24)                       */
    float negdot       /* 4    @ 0x28 */
    ??    unknown3     /* 4    @ 0x2c */
} RTSOLIDITY;          /* TOTAL: 0x30 */



struct ???? proc0x8038156c(LINKEDLISTNODE *arg1, short x, short y, short z, float *py /* [sp + 0x48] */);
{

    RTSOLIDITY *rts;     /* t0          */
    
    RTSOLIDITY *match    /* [sp + 0x04] */
    
    float plane_y        /* [sp + 0x08] */
    float negdot         /* [sp + 0x0c] */
    float norm_x         /* [sp + 0x18] */
    float norm_y         /* [sp + 0x14] */
    float norm_z         /* [sp + 0x10] */


    match = NULL;
    while (arg1) {
    
        rts = arg1->off0x04
        arg1 = arg1->off0x00
        
        if ((rts->pts[0][2] - z)*(rts->pts[1][0] - rts->pts[0][0])-(rts->pts[0][0] - x)*(rts->pts[1][2] - rts->pts[0][2]) < 0) {
            continue;
        }
        
        if ((rts->pts[1][2] - z)*(rts->pts[2][0] - rts->pts[1][0])-(rts->pts[1][0] - x)*(rts->pts[2][2] - rts->pts[1][2]) < 0) {
            continue;
        }
        
        if ((rts->pts[2][2] - z)*(rts->pts[0][0] - rts->pts[2][0])-(rts->pts[2][0] - x)*(rts->pts[0][2] - rts->pts[2][2]) < 0) {
            continue;
        }
        
        if (*(0x80361180)) {
            if (rts->unknown1 & 2) {
                continue;
            }
        } else {
            if (rts->command == 0x72) {
                continue;
            }
        }
        
        norm_x = rts->norm[0];
        norm_y = rts->norm[1];
        norm_z = rts->norm[2];
        negdot = rts->negdot;
        
        if (norm_y == 0) {          /* cull vertical triangles */
            continue;
        }
        
        plane_y = -(x*norm_x + norm_z*z + negdot) / norm_y;
        
        if ((float)y + 78.0 < plane_y) {      /* orig  ((float)y - plane_y + 78.0 < 0) */
            continue;
        }
        
        *py = plane_y;
        
        match = rts;
        break;
    }
    
    return match;
}
